package com.example;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import junit.framework.TestCase;

import java.util.Collections;

/**
 * 代码生成器
 */
public class CodeGen extends TestCase {
    public void test_gen() {
        final String url = "jdbc:mysql://localhost:13306/xbrother-bom?serverTimezone=GMT%2B8&characterEncoding=utf8";
        final String username = "root";
        final String password = "";
        FreemarkerTemplateEngine freemarkerTemplateEngine = new FreemarkerTemplateEngine();
        FastAutoGenerator.create(url, username, password)
                .globalConfig(builder -> {
                    builder.author("hcj") // 设置作者
                            //.enableSwagger() // 开启 swagger 模式
                            .disableOpenDir()
                            .outputDir("D:\\workspace-demo\\easy-rule-demo\\src\\main\\java"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder
                            .parent("com.example") // 设置父包名
                            .moduleName("xbrother") // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.xml, "D:\\workspace-demo\\easy-rule-demo\\src\\main\\resources\\mapper")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude("t_material","t_order", "t_order_item")// 设置需要生成的表名
                    // 设置过滤表前缀
                    .addTablePrefix("t_");
                })
                .strategyConfig(builder -> {
                    builder.entityBuilder()
                            .enableLombok()
                            .enableFileOverride()
                            .mapperBuilder()
                            .enableBaseColumnList()
                            .enableBaseResultMap()
                            .enableFileOverride()
                            .serviceBuilder()
                            .enableFileOverride()
                            .controllerBuilder()
                            .enableRestStyle()
                            .enableFileOverride()

                    ;
                })
                // 使用Freemarker引擎模板，默认的是Velocity引擎模板

                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}
